package com.cecsmsserve.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cecsmsserve.entity.ActivityType;
import com.cecsmsserve.mapper.ActivityTypeMapper;
import com.cecsmsserve.service.IActivityTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cecsmsserve.util.result.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 王郝浠
 * @since 2024-04-17
 */
@Service
public class ActivityTypeServiceImpl extends ServiceImpl<ActivityTypeMapper, ActivityType> implements IActivityTypeService {

    @Autowired
    ActivityTypeMapper mapper;

    @Override
    public CommonResult selectAll() {
        List<ActivityType> list=mapper.selectAll();
        CommonResult result=new CommonResult(list);
        if(list==null||list.size()==0){
            result.setNotFound();
        }
        return result;
    }

    @Override
    public CommonResult selectByName(String name) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("type",name);
        List<ActivityType> list=mapper.selectList(queryWrapper);
        CommonResult result=new CommonResult(list);
        if(list==null|list.size()==0){
            result.setNotFound();
        }
        return result;
    }

    @Override
    public CommonResult selectByState1() {
        List<ActivityType> list=mapper.selectByState1();
        CommonResult result=new CommonResult(list);
        if(list==null||list.size()==0){
            result.setNotFound();
        }
        return result;
    }

    @Override
    public CommonResult insert(ActivityType activityType) {
        int i=mapper.insert(activityType);
        CommonResult result=new CommonResult(i);
        if(i<=0){
            result.setNotInserted();
        }
        return result;
    }

    @Override
    public CommonResult update(ActivityType activityType) {
        int i=mapper.updateById(activityType);
        CommonResult result=new CommonResult(i);
        if(i<=0){
            result.setNotUpdate();
        }
        return result;
    }
}
